module data_mem #(
    parameter WIDTH = 32
) (
    //input                   clk,
    input       [WIDTH-1:0] A,
    input                   EN,
    input       [3:0]       WM,
    input                   WE,
    input       [31:0]      WD,
    output reg  [31:0]      RD,
    input       [31:0]      pc,
    output      [31:0]      instr
);

import "DPI-C" function int cpu_pmem_read(input int raddr);
import "DPI-C" function void cpu_pmem_write(input int waddr, input int wdata, input byte wmask);

always @(*) begin
    if(EN) begin
        RD = cpu_pmem_read(A);
        if (WE) begin // 有写请求时
            cpu_pmem_write(A, WD, 4); 
        end
    end
    else begin
        RD = 32'b0;
    end
end

assign instr = cpu_pmem_read(pc);
    
endmodule
